/* 
 * File:   FileOperator.cpp
 * Author: itu
 * 
 * Created on November 26, 2011, 3:19 PM
 */
#include <fstream>
#include "FileOperator.h"

FileOperator::FileOperator(string name) {
    fileName = name;
    isFileOpen = false;
}

bool FileOperator::openFileForReading(){
    if(!isFileOpen){
        file.open(fileName.c_str(), ios::in);
    }
    if(!file.fail()){
        isFileOpen = true;
        return true;
    }
    return false;
}

bool FileOperator::openFileForWriting(){
    if(!isFileOpen){
        file.open(fileName.c_str(), ios::out);
    }
    if(!file.fail()){
        isFileOpen = true;
        return true;
    }
    return false;
}

bool FileOperator::closeFile(){
    if(isFileOpen){
        file.close();
        isFileOpen=false;
        return true;
    }
    return false;
}

bool FileOperator::hasNextLine(){
    if(getline(file,line))
        return true;
    return false;
}

string FileOperator::getLine(){
    return line;
}
